package com.example.DAO.impl;

import com.example.DAO.DBUtilsDAO;
import com.example.DAO.UserDao;
import com.example.pojo.User;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpI implements UserDao {
    private DBUtilsDAO dbConnection = DBUtilsFactory.getDBConnection();

    public UserDaoImpI() {
    }

    public User findByUserName(String usernameFromIndex) {
        String sql = "select * from user where user_name=?";

        try {
            Object var15;
            try (Connection conn = this.dbConnection.getConnection()) {
                try (PreparedStatement prep = conn.prepareStatement(sql)) {
                    prep.setString(1, usernameFromIndex);
                    ResultSet rs = prep.executeQuery();
                    if (rs.next()) {
                        String password = rs.getString("user_password");
                        String identity = rs.getString("identity");
                        User user = new User(usernameFromIndex, password, identity);
                        User var9 = user;
                        return var9;
                    }

                    var15 = null;
                }
            }

            return (User)var15;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}